// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2023 Yevhen Babiichuk (DustDFG)

#ifndef _VIEW_HPP_
#define _VIEW_HPP_

#include <SFML/System/Clock.hpp>

#include <SFML/Graphics/RenderWindow.hpp>

#include <string>
#include <optional>

#include <SFML/Graphics.hpp>

#include <DotSort/View/IView.hpp>
#include <Abracadabra/View/Theme.hpp>
#include <Abracadabra/View/Tube.hpp>

#include <Abracadabra/Presenter.hpp>

namespace View
{

class View : public IView, public sf::Drawable
{
	private:
		uint8_t tubeSize;
		uint8_t tubeCount;

		mutable std::vector<Tube> tubes;

		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;

		Theme* theme;

		Presenter* presenter;

		sf::RectangleShape topBar;

		sf::Texture reloadTexture;
		sf::RectangleShape reloadButton;

		sf::FloatRect gameRect;

		void calculateGeometry(uint8_t tubeSize, uint8_t tubeCount);

		std::optional<uint8_t> getTubeIndex(sf::Vector2f click) const;

		void onClick(sf::Vector2f click);

	public:
		View(sf::Vector2u windowSize);
		virtual ~View();

		void processEvent(sf::Event event);

		void onNewLevel(uint8_t tubeSize, uint8_t tubeCount) override;
		void update(uint8_t tubeIndex, const std::vector<uint8_t>& dots) override;
};

}

#endif
